# Makefile for AE

uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')

CC = gcc
CFLAGS = -O2 -Wall -D AE_MAKEFILE
LDFLAGS = -shared

TARGET = libae
INCLUDES = $(wildcard *.h)
SOURCES = $(wildcard *.c)
OBJS = $(patsubst %.c,%.o,$(SOURCES))

ifeq ($(uname_S),Linux)
	CFLAGS += -D AE_LINUX -fPIC
	LDFLAGS += -lpthread
	TARGET := $(TARGET).so
else
ifeq ($(uname_S),FreeBSD)
	CFLAGS += -D AE_FREEBSD -fPIC
	LDFLAGS += -lpthread
	TARGET := $(TARGET).so
else
ifneq (,$(findstring MINGW,$(uname_S)))
	CFLAGS += -D AE_WIN32
	LDFLAGS += -lws2_32 -lmswsock -static-libgcc
	TARGET := $(TARGET).dll
else
	$(error Unsupport platform for compile AE)
endif
endif
endif

all: lib

%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

$(OBJS): $(SOURCES) $(INCLUDES)

lib: $(OBJS)
	$(CC) -o $(TARGET) $(OBJS) -shared $(LDFLAGS)

clean:
	$(RM) *.o *~ $(TARGET)
